package view.Professeurs;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;

import Controller.CompteController;

import view.Fenetre;
import view.Param;
import view.Accueil.LogPanel;

@SuppressWarnings("serial")
public class LeftPanel extends JPanel implements ActionListener {

	private JButton bExit;

	public LeftPanel() {

		// Agencement des conteneurs
		GridBagConstraints constraint = new GridBagConstraints();
		this.setLayout(new GridBagLayout());

		// Creation des conteneurs
		JLabel lTitre = new JLabel("ETUDIANTS");
		ArboPanel pArbo = new ArboPanel();
		ExosButtonsPanel pMid = new ExosButtonsPanel();
		bExit = new JButton("D\u00E9connexion");

		// Ajout de la transparence
		this.setOpaque(false);

		// Ajout des couleurs
		lTitre.setForeground(Param.fontColor);


		// CONTRAINTE DU LABEL DE TITRE

		constraint.gridx = 1;
		constraint.gridy = 0;

		constraint.weightx = 1.0;
		constraint.weighty = GridBagConstraints.NONE;

		constraint.gridwidth = GridBagConstraints.REMAINDER;
		constraint.gridheight = 1;

		constraint.fill = GridBagConstraints.CENTER;

		this.add(lTitre, constraint);


		// CONTRAINTE DU PANNEAU D'ARBORESCENCE

		constraint.gridy = 1;

		constraint.weighty = 0.7;

		constraint.gridwidth = GridBagConstraints.REMAINDER;
		constraint.gridheight = 7;

		constraint.fill = GridBagConstraints.BOTH;

		this.add(pArbo, constraint);



		// CONTRAINTE DU PANEL DE CRÉATION ET SUPPRESSION

		constraint.gridy = 8;

		constraint.weighty = 0.1;

		constraint.gridwidth = GridBagConstraints.REMAINDER;
		constraint.gridheight = 1;

		constraint.fill = GridBagConstraints.BOTH;

		this.add(pMid, constraint);

		// CONTRAINTE DU BOUTON DE DECONNEXION

		constraint.gridy = 9;

		constraint.weighty = GridBagConstraints.NONE;

		constraint.gridwidth = GridBagConstraints.REMAINDER;
		constraint.gridheight = 1;

		constraint.fill = GridBagConstraints.CENTER;

		this.add(bExit, constraint);

		// FIN DES CONTRAINTES


		// Ajout des marges
		this.setBorder(Param.wideMargin);
		Border margin = BorderFactory.createEmptyBorder(0, 0, 10, 0);		// top, left, bottom, right
		lTitre.setBorder(margin);

		// Ajout des ecouteurs aux boutons
		bExit.addActionListener(this);

	}

	@Override
	public void actionPerformed(ActionEvent event) {

		if (event.getSource() == bExit) {

			CompteController log;
			log = Fenetre.control.CompteController();
			log.deconnexion();
			LogPanel.wProf.erase();

			Fenetre.fen.refresh();

		}

	}

}
